<?php
namespace app\blog\controller;
use cmf\controller\AdminBaseController;
use think\Db;

class SingleController extends AdminBaseController
{
    public function slist(){
        $uid=cmf_get_current_admin_id();
        $request = input('request.');
        $storeid = $this->request->param('storeid');
        $where ='d.storeid ='.$storeid;
        $where.=' and d.paystatus=1';

        if(!empty($request['start_time'])){
            $where .= ' and DATE( FROM_UNIXTIME( d.ctime ) ) >= "'.$request['start_time'].'"';
        }else{
            $where .= ' and DATE( FROM_UNIXTIME( d.ctime ) ) >= "'.date('Y-m-d',time()).'"';
        }
        if(!empty($request['end_time'])){
            $where .= ' and DATE( FROM_UNIXTIME( d.ctime ) ) <= "'.$request['end_time'].'"';
        }
        $order='';
        $norder=isset($request['norder'])?$request['norder']:'';
        if($norder ==2){
            $order='num desc';
        }elseif($norder ==1){
            $order='num asc';
        }
        $morder=isset($request['morder'])?$request['morder']:'';
        if($morder ==2){
            if(strlen($order)){
                $order.=',money desc';
            }else{
                $order='money desc';
            }
        }elseif($morder ==1){
            if(strlen($order))
            {
                $order.=',money asc';
            }else{
                $order='money asc';
            }
        }
        //各个查询条件
        $list=Db::name('order_detail')->alias('d')->join('store s','s.id=d.storeid')->where($where)->order($order)
        ->field('d.id,s.store_name,d.g_goodsname,d.stemeal,d.ctime,sum(d.count) as num,sum(d.total) as money')->group('d.goodsid')->paginate(10);
        $list->appends($request);
        $this->assign("page", $list);
        $this->assign("storeid", $storeid);
        $this->assign("list", $list);
        return $this->fetch();
    }
}